﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class aspnet_admin_bock_News_CX_News_Probject_Edit : System.Web.UI.Page
{

    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();


    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();


    /// <summary>
    /// id
    /// </summary>
    string id = "";

    public string str = "";
    DataTable NewDt = new DataTable();
    public Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Button2.Attributes.Add("onclick", "window.open('../../inc/UpFile.aspx?formname=aspnetForm&amp;editname=" + CX_NEWS_Class_Pic.ClientID.ToString() + "&amp;uppath=UpFile','','status=no,scrollbars=no,top=20,left=110,width=600,height=265')");
            //帮字数据
            BindData();
            CX_Column_id.Attributes.Add("onchange", "CXgetVlaues(this.value);");//使用ajaxpro动态改变值
            
        }
    }


    protected void PageSave(int id)
    {



        try
        {
            
            int.Parse(CX_Column_id.Text.Trim());
        }
        catch
        {
            tt.Text = "输入排序不能转换";
            Response.End();
        }
        if (CX_NEWS_Class_Name.Text.Trim() != "" && CX_NEWS_Class_Itemplitate_Address.Text.Trim() != "" && CX_NEWS_Class_Itemplitate_Parame.Text.Trim() != "")
        {

            TextData.SqlDataSave("update [CX_NEWS_Class] Set  CX_NEWS_Class_Name='" + CX_NEWS_Class_Name.Text.Trim() + "',CX_Column_id = " + CX_Column_id.SelectedValue.Trim() + ",CX_NEWS_Class_Explier='" + CX_NEWS_Class_Explier.Text.Trim() + "',CX_NEWS_Class_Itemplitate_Address='" + CX_NEWS_Class_Itemplitate_Address.Text.Trim() + "',CX_NEWS_Class_Itemplitate_Parame='" + CX_NEWS_Class_Itemplitate_Parame.Text.Trim() + "',CX_NEWS_Class_Pic='" + CX_NEWS_Class_Pic.Text.Trim() + "',CX_NEWS_Class_CreateFielfront='" + CX_NEWS_Class_CreateFielfront.Text.Trim() + "',CX_NEWS_Class_Directory='" + CX_NEWS_Class_Directory.Text.Trim().Replace("'","").Replace("\"","") + "'  where CX_NEWS_Class_id=" + id); 
            tt.Text = "更新新闻设定" + CX_NEWS_Class_Name.Text + "成功";
    //        tt.Text = "update [CX_NEWS_Class] Set  CX_NEWS_Class_Name='" + CX_NEWS_Class_Name.Text.Trim() + "',CX_Column_id = " + CX_Column_id.SelectedValue.Trim() + ",CX_NEWS_Class_Explier='" + CX_NEWS_Class_Explier.Text.Trim() + "',CX_NEWS_Class_Itemplitate_Address='" + CX_NEWS_Class_Itemplitate_Address.Text.Trim() + "',CX_NEWS_Class_Itemplitate_Parame='" + CX_NEWS_Class_Itemplitate_Parame.Text.Trim() + "',CX_NEWS_Class_Pic='" + CX_NEWS_Class_Pic.Text.Trim() + "',CX_NEWS_Class_CreateFielfront='" + CX_NEWS_Class_CreateFielfront.Text.Trim() + "'  where CX_NEWS_Class_id=" + id;
            BindData();
        }
        else
        {
            tt.Text = "输入的信息内容不正确";
        }





        
    }



    void BindData()
    {
        try
        {
            id = Request.QueryString["id"].Trim();
            int.Parse(id);
            MyDt = TextData.SqlataSet("select * from [CX_NEWS_Class] where CX_NEWS_Class_id=" + id + "").Tables[0];

            NewDt.Columns.Add("东东");
            NewDt.Columns.Add("Conts");
            ShowTree(0);
            CX_Column_id.DataSource = NewDt.DefaultView;
            CX_Column_id.DataTextField = "Conts";
            CX_Column_id.DataValueField = "东东";
            CX_Column_id.SelectedValue = MyDt.Rows[0]["CX_Column_id"].ToString().Trim();
            CX_Column_id.DataBind();

            CX_NEWS_Class_Name.Text = MyDt.Rows[0]["CX_NEWS_Class_Name"].ToString().Trim();
            CX_NEWS_Class_Explier.Text = MyDt.Rows[0]["CX_NEWS_Class_Explier"].ToString().Trim();
            CX_NEWS_Class_Itemplitate_Address.Text = MyDt.Rows[0]["CX_NEWS_Class_Itemplitate_Address"].ToString().Trim();
            CX_NEWS_Class_Itemplitate_Parame.Text = MyDt.Rows[0]["CX_NEWS_Class_Itemplitate_Parame"].ToString().Trim();
            CX_NEWS_Class_Pic.Text = MyDt.Rows[0]["CX_NEWS_Class_Pic"].ToString().Trim();
            CX_NEWS_Class_CreateFielfront.Text = MyDt.Rows[0]["CX_NEWS_Class_CreateFielfront"].ToString().Trim();
            CX_NEWS_Class_Directory.Text = MyDt.Rows[0]["CX_NEWS_Class_Directory"].ToString().Trim();
        }
        catch
        {
            MyDt = TextData.SqlataSet("select * from [CX_NEWS_Class]  ").Tables[0];

            NewDt.Columns.Add("东东");
            NewDt.Columns.Add("Conts");
            ShowTree(0);
            CX_Column_id.DataSource = NewDt.DefaultView;
            CX_Column_id.DataTextField = "Conts";
            CX_Column_id.DataValueField = "东东";
            CX_Column_id.DataBind();

            CX_NEWS_Class_Name.Text = MyDt.Rows[0]["CX_NEWS_Class_Name"].ToString().Trim();
            CX_Column_id.Text = MyDt.Rows[0]["CX_Column_id"].ToString().Trim();
            CX_NEWS_Class_Explier.Text = MyDt.Rows[0]["CX_NEWS_Class_Explier"].ToString().Trim();
            CX_NEWS_Class_Itemplitate_Address.Text = MyDt.Rows[0]["CX_NEWS_Class_Itemplitate_Address"].ToString().Trim();
            CX_NEWS_Class_Itemplitate_Parame.Text = MyDt.Rows[0]["CX_NEWS_Class_Itemplitate_Parame"].ToString().Trim();
            CX_NEWS_Class_Pic.Text = MyDt.Rows[0]["CX_NEWS_Class_Pic"].ToString().Trim();
            CX_NEWS_Class_CreateFielfront.Text = MyDt.Rows[0]["CX_NEWS_Class_CreateFielfront"].ToString().Trim();
            CX_NEWS_Class_Directory.Text = MyDt.Rows[0]["CX_NEWS_Class_Directory"].ToString().Trim();
        }

        Chenge(CX_Column_id.SelectedValue);
       
    }

    int ii = 0;
    /// <summary>
    /// 返回菜单显示的HTML代码
    /// </summary>
    /// <param name="select">显示的展次</param>
    /// <returns></returns>
    public void ShowTree(int select)
    {
        string sql;
        int i = 0;
        DataTable MyDt = new DataTable();
        sql = "Select * From CX_Column where CX_Column_LX<>3 and CX_Column_followid =" + select + " order by CX_Column_id desc";
        try
        {

            MyDt = TextData.SqlataSet(sql).Tables[0];//创建DataTable MyDt
        }
        catch (Exception ex)
        {
            TextData.Err(ex.Message);

        }
        for (i = 0; i < MyDt.Rows.Count; i++)//遁环记录集
        {
            if (select == 0)//如果只一有层的话
            {

                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            else
            {
                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            ii = ii + 1;
            ShowTree(int.Parse(MyDt.Rows[i]["CX_Column_id"].ToString()));//调用自己显示菜单ＨＴＭＬ
            ii -= 1;

        }


    }



    /// <summary>
    /// ajax模式
    /// </summary>
    /// <param name="Sid"></param>
    /// <returns></returns>
    public String Chenge(string Sid)
    {

        if (Sid != "")
        {
            str = "    var ajax=new AJAXRequest();ajax.post('CX_News_Write_Itemp.ashx?id='+Id,'t=" + CX_NEWS_Class_Itemplitate_Address.ClientID + "&p=" + CX_NEWS_Class_Itemplitate_Parame.ClientID + "&d=" + CX_NEWS_Class_Directory.ClientID + "',function(obj) { eval(obj.responseText); });";
        }
        return str;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            id = Request.QueryString["id"].Trim();

            PageSave(int.Parse(id));
        }
        catch
        {
            Response.Write("");
        }
    }
}
